import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Print from 'vue-print-nb'
// 引入vuex
import store from './store/index'

// 导入全局样式
import './assets/css/global.css'
// 引入icon字体图标
import './assets/css/fonts/iconfont.css'

// 引入axios
import axios from 'axios'

import './plugins/element.js'
// 设置axios默认地址 http://47.106.215.185:80/ http://localhost:80
axios.defaults.baseURL = 'http://localhost:80'
// 挂载axios
Vue.prototype.$http = axios

// 请求拦截
axios.interceptors.request.use(config => {
  // 在请求头中携带token信息
  config.headers.Authorization = window.localStorage.getItem('token')
  // 最后一定要return出config
  return config
})

// 响应拦截
axios.interceptors.response.use((config) => {
  if (config.data === 'Token Error') {
    alert('Token 验证失败, 请重新登陆')
  }
  return config
})

// 全局过滤器,处理事件格式
Vue.filter('dateFormat', function(originVal) {
  if (originVal === null) {
    return '未选择'
  }
  const date = new Date(originVal)
  const y = date.getFullYear()
  const m = (date.getMonth() + 1 + '').padStart(2, '0')
  const d = (date.getDate() + '').padStart(2, '0')
  const hh = (date.getHours() + '').padStart(2, '0')
  const mm = (date.getMinutes() + '').padStart(2, '0')
  const ss = (date.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

Vue.config.productionTip = false

Vue.use(Print)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
